class InvitedController < ApplicationController

  def index
    if i = params[:i]
    flash[:notice] = "You earned #{i*PointConfig.find_by_name("invite_sent").point} WinPoints via your invite request(s)."
    end
    redirect_to buy_wins_path
  end
  def from_chat
      uid = params[:id]
      #unless PointHistory.exists?(["action='invite friend from chat' and related_user_id=?",uid])
        PointHistory.create(:user_id=>nil,:action=>'invite friend from chat',:point=>PointConfig.find_by_name("invite_sent").point,:earning => true,:related_user_id=>uid)
        #user = User.find(uid)
        #user.point = user.point + PointConfig.find_by_name("invite_sent").point
        #user.save
      #end
     redirect_to bets_path
  end
  def after_joined
     phs = PointHistory.find(:all,:conditions=>["user_id is NULL and action='invite friend from chat' and created_at > ?",1.day.ago],:order=>"id desc")
     phs.each do |ph|
     if params[:fb_sig_friends].match(ph.related_user_id.to_s)
        user = User.find(ph.related_user_id)
        user.point = user.point + PointConfig.find_by_name("invite_sent").point + PointConfig.find_by_name("invite_received").point
	#user.invitation_sent_number = user.invitation_sent_number.to_i + 1
	user.invitation_accept_number = user.invitation_accept_number.to_i + 1
        user.save
	ph.user_id = params[:fb_sig_user]
	ph.save
     end
     end
     redirect_to bets_path
  end
end
